package tfc_editor.userManagement;

/**
 * Excepcio que es llenca quan es produeix un error relacionat amb com manejem els usuaris.
 * @author Ismael Gonzalez Burgos
 *
 */
public class UserManagementException extends Exception
{
	private static final long serialVersionUID = 1L;
	private int errorreason;
	public static final int USER_ALREADY_EXISTS	= 1;
	public static final int INDEX_OUT_OF_BOUNDS = 2;
	public static final int USER_DOESNT_EXIST	= 3;
	public static final int INVALID_PASSWORD	= 4;
	
	/**
	 * Constructor de la classe.
	 * @param reason Rao de l'error.
	 */
	UserManagementException(int reason)
	{
		errorreason = reason;
	}
	
	/**
	 * Funcio que retorna un missatge d'error depenent de l'error que l'hagi generat. 
	 */
	public String getLocalizedMessage()
	{
		switch (errorreason)
		{
			case USER_ALREADY_EXISTS:
				return "UserManagementException:: Cannot create user, reason: User already exists";
			case INDEX_OUT_OF_BOUNDS:
				return "UserManagementException:: Index is out of bounds";
			case USER_DOESNT_EXIST:
				return "UserManagementException:: Any user with this login";
			case INVALID_PASSWORD:
				return "UserManagementException:: Invalid password";
		}
		
		return "UserManagementException:: Unknown error";
	}
	
}
